package com.shiliu.api.controller;

import com.shiliu.api.TestUserControllerApi;
import com.shiliu.api.common.utils.JedisUtil;
import com.shiliu.api.service.TestIUserService;
import com.shiliu.model.entity.TestUser;
import com.shiliu.model.pojo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description: TODO
 * @author: shili
 * @created: 2019/12/18 14:45
 * @version: v1.0.0
 */
@RestController
@RequestMapping("/api/v1/test/user")
public class TestUserController implements TestUserControllerApi {

    @Autowired
    private TestIUserService userService;

    @Autowired
    private JedisUtil jedisUtil;

    @Override
    @PostMapping("/add")
    public ResponseResult save(@RequestBody TestUser user) {
        boolean save = userService.save(user);
        if(save){
            return ResponseResult.ok();
        }
        return ResponseResult.error();
    }

    @Override
    @PostMapping("/update")
    public ResponseResult update(@RequestBody TestUser user) {
        boolean update = userService.updateById(user);
        if(update){
            return ResponseResult.ok();
        }
        return ResponseResult.error();
    }

    @Override
    @GetMapping("/deleteById/{id}")
    public ResponseResult deleteById(@PathVariable("id") Long id) {
        boolean remove = userService.removeById(id);
        if(remove){
            return ResponseResult.ok();
        }
        return ResponseResult.error();
    }

    @Override
    @GetMapping("/queryById/{id}")
    public ResponseResult queryById(@PathVariable("id") Long id) {
        TestUser user = userService.getById(id);
        return ResponseResult.ok("success",10000,user);
    }

    @Override
    @PostMapping("/queryByPage/{currentPage}/{size}")
    public ResponseResult queryByPage(@PathVariable("currentPage") Integer currentPage,
                                      @PathVariable("size") Integer size,
                                      @RequestBody TestUser user) {
        ResponseResult result = userService.queryByPage(currentPage,size,user);
        return result;
    }

    @Override
    @PostMapping("/query")
    public ResponseResult query(@RequestBody TestUser user) {
        return null;
    }
}
